import { useSelector, useDispatch } from "react-redux"
import { changeName, changeAge } from "@/store/modules/userSlice"

const UserInfo = () => {
    const { name, age } = useSelector(state => state.user)
    const dispatch = useDispatch()

    const updateName = () => {
        dispatch(changeName('zs'))
    }

    const updateAge = () => {
        dispatch(changeAge(18))
    }
    return (
        <div>
            <div>name: { name }</div>
            <div>age: { age }</div>
            <button onClick={updateName}>更改名字</button>
            <button onClick={updateAge}>更改年龄</button>
        </div>
    )
}

export default UserInfo